package jucTest;

import java.util.concurrent.CountDownLatch;

/**
 * 加法计数器,人满就走
 */
public class CountDownLatchDemo {
    public static void main(String[] args) throws InterruptedException {
        CountDownLatch countDownLatch = new CountDownLatch(5);
        for (int i = 0; i < 5; i++) {
            new Thread(()->{
                System.out.println(Thread.currentThread().getName()+"来了");
                countDownLatch.countDown();
                System.out.println(Thread.currentThread().getName()+"end");
            },String.valueOf(i)).start();
        }
        countDownLatch.await();
        System.out.println("结束");
    }
}
